Ext.define("PCD.controller.PcdController",{
	extend: "Ext.app.Controller",

	views: [
		"pcd.PcdEdit",
		"pcd.PcdList"
	],

	stores: [
		"PcdStore"
	],

	models: [
		"PcdModel"
	],

	pcdView:null,

	init:function(){
		//console.log("PcdController init");
		this.control({
            'pcdlist dataview': {
                itemdblclick: this.showPcd
            },
            "pcdedit button[action=apply]":{
            	click: this.updatePcd
            },
            "pcdedit button[action=delete]":{
            	click: this.deletePcd
            }
        });
	},

	deletePcd:function(button){
		var win    = button.up('window'),
        form   = win.down('form'),
        record = form.getRecord(),
        values = form.getValues();
		this.getPcdStoreStore().remove(record);
		this.getPcdStoreStore().sync();
		win.hide();
	},

	updatePcd:function(button){
		var win    = button.up('window'),
        form   = win.down('form'),
        record = form.getRecord(),
        values = form.getValues();

    	record.set(values);
    	this.getPcdStoreStore().sync();
    	win.hide();
	},

	showPcd:function(grid, record){
		if(!this.pcdView){
			this.pcdView = Ext.create("PCD.view.pcd.PcdEdit");
		}
		this.pcdView.down('form').loadRecord(record);
		this.pcdView.show();
	}
});